{block name=body}
    {* Define the function *}
    {function name=render_list level=0}
        {foreach $items as $item}
            {if $item.url}
                <tr {if $item.published eq '0'}class="draft"{/if}>
                    <td><b>{$item.record.news_start_date|date_format:"%Y-%m-%d"}</b></td>
                    <td>{for $var=1 to $level}- {/for}<b>{$item.title} </b>{if $item.published eq '0'}
                        <small>| 草稿</small>{/if}</td>
                    <td>{if $item.url}
                            <a href='{$item.url}' class='btn btn-small btn-warning pull-right'><span
                                        class="glyphicon glyphicon-pencil"></span> Edit</a>
                        {/if}
                    </td>
                    <td>{if $item.url_delete}
                            <a href='{$item.url_delete}' onclick="return ConfirmDelete();"
                               class='btn btn-small btn-danger pull-right'><span
                                        class="glyphicon glyphicon-trash"></span> 删除</a>
                        {/if}
                    </td>
                </tr>
            {/if}
            {if count($item.subs) > 0} {call name=render_list items=$item.subs level=$level+1} {/if}
        {/foreach}
    {/function}
    <div class="row ">
        <table class="table table-bordered table-striped table-hover" id="newsListTable">
            <thead>
            <tr>
                <th colspan="8" class="text-center" style="font-size:1.2em;position:relative;">
                    <span>新闻列表</span>
                    <a href="/admin/general/newchange" class='btn btn-sm btn-success pull-right'
                       style="position: absolute;right: 1%;top: 50%;margin-top: -1.2em;"><span
                                class="glyphicon glyphicon-plus"></span> 添加新闻</a>
                </th>
            </tr>
            <tr>
                <th style="width:15%;">日期</th>
                <th>标题</th>
                <th>分类标签</th>
                <th>发布状态</th>
                <th colspan="4" style="text-align:center;position:relative;">
                    操作
                </th>
            </tr>
            </thead>
            <tbody>
            {foreach $newList as $new}
                <tr data-id="{$new.id}">
                    <td>
                        <span class="news-list-pub-date" style="font-size:1.5em;">{$new.start_time}</span>
                    </td>
                    <td>
                        <span class="news-list-title" style="font-size:1.5em;">{$new.title}</span>
                    </td>
                    <td>
                        <span class="news-list-tab" style="font-size:1.5em;">
                        {foreach $tabs as $tab}
                            {if $tab.id eq $new.news_title_id}
                                {$tab.title}
                            {/if}
                        {/foreach}
                        </span>
                    </td>
                    <td>
                        {if $new.publish eq '1'}
                            <span class="new-list-pub-state text-success" style="font-size:1.5em;text-align:center;">已发布</span>
                        {else}
                            <span class="new-list-pub-state text-danger" style="font-size:1.5em;text-align:center;">未发布</span>
                        {/if}
                    </td>
                    <td>
                            <button class="btn btn-info btn-sm pull-right news-list-publish" {if $new.publish eq '1'}style="display:none;"{/if}><span
                                        class="glyphicon glyphicon-bullhorn"></span> 发布
                            </button>
                            <button class="btn btn-default btn-sm pull-right news-list-unpublish"
                                    style="{if $new.publish eq '0'}display:none;{/if}background:#ddd!important;color:#e4393c!important;border-color:#ddd!important;">
                                <span class="glyphicon glyphicon-ban-circle"></span> 下架
                            </button>
                    </td>
                    <td class="preview-news">
                        {if $new.publish == '1'}
                        <a href="/our-program/news-info?articleid={$new.id}"
                           class="btn btn-info btn-sm pull-right news-list-edit"><span
                                    class="glyphicon glyphicon-eye-open"></span> 查看</a>
                        {else}
                            <a onclick="alert('该新闻未发布,不能进行查看')"
                               class="btn btn-info btn-sm pull-right news-list-edit"><span
                                        class="glyphicon glyphicon-eye-open"></span> 查看</a>
                        {/if}
                    </td>
                    <td>
                        <a href="/admin/general/newchange?newId={$new.id}"
                           class="btn btn-warning btn-sm pull-right news-list-edit"><span
                                    class="glyphicon glyphicon-pencil"></span> 编辑</a>
                    </td>
                    <td>
                        <button class='btn btn-sm btn-danger pull-right news-list-del'><span
                                    class="glyphicon glyphicon-trash"></span> 删除
                        </button>
                    </td>
                </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
    <input type="hidden" value="{$token}" id="formToken">
    <script>
        (function(){
            $(".news-list-tab").each(function(){
                if($(this).html().trim()==''){
                    $(this).html('未分类').addClass('text-danger');
                }
            });

            //删除新闻
            $(".news-list-del").on('click',function(e){
                e.preventDefault();
                var newid=$(this).parents('tr[data-id]').attr('data-id');
                var params={};
                params.id=newid;
                params.type='delete';
                $.post('../includes/processes/processes-news-controller.php',params,function(data){
                    console.log(data);
                    if(data.type=='1'){
                        $("#newsListTable tr[data-id='"+params.id+"']").remove();
                    }
                    commonAlertBox(data.content);
                },'json');
            });

            //发布新闻
            $(".news-list-publish,.news-list-unpublish").on('click',function(e){
                e.preventDefault();
                if($(this).parents("tr[data-id]").find(".news-list-tab").hasClass("text-danger")){
                    commonAlertBox("请将新闻编辑分类后再发布");
                }else{
                    var newid=$(this).parents('tr[data-id]').attr('data-id');
                    var params={};
                    params.id=newid;
                    params.formToken=$("#formToken").val();
                    params.type='edit_publish';
                    if($(this).hasClass('news-list-publish')){
                        params.publish=1;
                    }else{
                        params.publish=0;
                    }
                    var $this=this;
                    $.post('../includes/processes/processes-news-controller.php',params,function(data){
                        console.log(data);
                        if(data.type=='1'){
                            $($this).hide();
                            $($this).siblings().show();
                            if(params.publish==1){
                                $($this).parents('tr[data-id]').find('.new-list-pub-state')
                                        .html('已发布').removeClass('text-danger').addClass('text-success');
                                $($this).parents('tr[data-id]').find('.preview-news').html("<a href='/our-program/news-info?articleid="+newid+"' class='btn btn-info btn-sm pull-right news-list-edit'><span class='glyphicon glyphicon-eye-open'></span> 查看</a>");
                            }else{
                                $($this).parents('tr[data-id]').find('.new-list-pub-state')
                                        .html('未发布').removeClass('text-success').addClass('text-danger');
                                var innertext='该新闻未发布,不能进行查看';
                                $($this).parents('tr[data-id]').find('.preview-news').html("<a onclick='alert(\""+innertext+"\")' class='btn btn-info btn-sm pull-right news-list-edit'><span class='glyphicon glyphicon-eye-open'></span> 查看</a>");
                            }
                        }
                        commonAlertBox(data.content);
                    },'json');
                }
            });
        })();
    </script>
{/block}



